home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Arsenal Files 4
/
The Arsenal Files 4 (Arsenal Computer).ISO
/
casm
/
au116-as.exe
/
DIR.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-12
|
6KB
|
238 lines
// dir.CPP 1 1 6666
// Dave Harris 11 11 6
// Compiled using Borland C++ ver 3.1 1 1 1 1 6666
// 03-03-94 1 .. 1 6 6
// 11111 .. 11111 666
////////////////////////////////////////////////////////////////////////
#include "au.hpp"
#include <time.h>
/*********************************************************************/
/* Define Statements */
/*********************/
#define PROGRAM "DIR" // Name of module
typedef struct
{
char list_order[50];
} DIR_INFO;
/*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
static int dir(AU *au, char *file_name)
{
DIR_INFO *in = (DIR_INFO *)au->info;
struct ffblk ffblk; // directory entry structure
int i;
int size;
DATE date1, date2;
date datep;
char temp[FILE_SIZE];
char disp_string[200];
char piece[80];
char *ptr;
check_for_key();
disp_string[0] = '\0';
if (!findfirst(file_name, &ffblk, 0))
{
i=0;
while (in->list_order[i] != '\0')
{
size = 0;
if (isdigit(in->list_order[i]))
{
size = atoi(in->list_order+i);
if (size > 32 || size < 0)
{
au_printf_error(au, "Illegal size specifier (%d)", size);
exit(1);
}
i = i + ((size < 10) ? 1 : 2);
if (in->list_order[i] == '\0')
{
au_printf_error(au, "Size specifier not attached to an order");
exit(1);
}
}
switch (in->list_order[i])
{
case 'A':
getdate(&datep); // Current date */
date1.year = datep.da_year - 1900;
date1.month = datep.da_mon;
date1.day = datep.da_day;
fdate_to_date(&date2, &ffblk);
if (size == 0)
size = 6;
sprintf(piece, "%*ld", size, days_diff(&date2, &date1));
break;
case 'D':
fdate_to_date(&date1, &ffblk);
if (size == 0)
size = 8;
sprintf(piece, "%*s", size, date_to_string(&date1));
break;
case 'E':
if (size == 0)
size = FILE_EXT-1;
ptr = strchr(file_name, '.');
if (ptr != NULL)
sprintf(piece, "%-*s", size, ptr+1);
break;
case 'N':
if (size == 0)
size = FILE_SIZE-1;
sprintf(piece, "%-*s", size, file_name);
break;
case 'P':
strcpy(temp, file_name);
ptr = strchr(temp, '.');
if (ptr != NULL)
*ptr = '\0';
if (size == 0)
size = FILE_PREF-1;
sprintf(piece, "%-*s", size, temp);
break;
case 'S':
if (size == 0)
size = 10;
sprintf(piece, "%*ld", size, ffblk.ff_fsize);
break;
case 'T':
sprintf(temp, "%02d:%02d:%02d",
(ffblk.ff_ftime & 0xF800) >> 11,
(ffblk.ff_ftime & 0x07E0) >> 5,
(ffblk.ff_ftime & 0x001F) * 2);
if (size == 0)
size = 8;
sprintf(piece, "%*s", size, temp);
break;
case 'X':
if (size == 0)
size = 4;
sprintf(piece, "%0*x", size, crc16(au, file_name));
break;
case 'Y':
if (size == 0)
size = 8;
sprintf(piece, "%0*lx", size, crc32(au, file_name));
break;
case '_':
sprintf(piece, "");
break;
case '.':
{
int len = strlen(disp_string);
if (len > 0)
disp_string[len-1] = '\0';
i++;
continue;
}
default:
au_printf_error(au, "Unknown list piece '%c'", in->list_order[i]);
exit(1);
}
strcat(disp_string, piece);
strcat(disp_string, " ");
i++;
}
au_printf(au, "%s", disp_string);
safe_string_copy(au->env_cont, disp_string, CLENGTH, FALSE);
au_printf(au, "\n");
}
return 0;
}
/*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
static void ReadCFGInfo(AU *au, CFG_HANDLE *cfg_handle)
{
char string[200],
string2[200],
string3[200];
DIR_INFO *in = (DIR_INFO *)au->info;
for(EVER)
{
if (cfg_handle->read_line(au, string)==EOF)
break;
split_string(string, string2);
split_string(string, string3);
if (string2[0] == '\0')
continue;
strcpy(au->curOpt,string2);
au->curVal = string3;
switch (toupper(string2[1]) << 8 | toupper(string2[0]))
{
case 'BE': // Begin
return;
case 'LI': // List_Order
strcpy(in->list_order, string3);
break;
default:
cfg_handle->invalid_option(au, string2);
}
}
}
/*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
static BYTE parse_comm_line(AU *au, char option, char *cur_argv,
PARSE_TYPE type)
{
DIR_INFO *in = (DIR_INFO *)au->info;
switch (type)
{
case PARSE_PARAM_OPTION:
switch (option)
{
case 'L':
safe_string_copy(in->list_order, cur_argv, 30, FALSE);
strupr(in->list_order);
break;
case '?':
au_standard_opt_header(au, "DIr",
"@?3-L@?Dx@?H @?3L@?Hist order, where @?Dx@?H = string of:\n"
" @?DA@?H - @?DA@?Hge\n"
" @?DD@?H - @?DD@?Hate\n"
" @?DE@?H - file @?DE@?Hxtension\n"
" @?DN@?H - file @?DN@?Hame\n"
" @?DP@?H - file @?DP@?Hrefix\n"
" @?DS@?H - @?DS@?Hize\n"
" @?DT@?H - @?DT@?Hime\n"
" @?DX@?H - 16 bit CRC\n"
" @?DY@?H - 32 bit CRC\n"
" @?D_@?H - Extra space\n"
" @?D.@?H - No space between\n"
"\n"
" In front of each, an optional size specifier may be placed\n");
exit (0);
default:
au_invalid_option(au, PROGRAM, option);
}
return TRUE;
}
return FALSE;
}
/*░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░*/
int main_dir(AU *au, int argc, char *argv[])
{
DIR_INFO *in;
in = new DIR_INFO;
memset(in, '\0', sizeof(DIR_INFO));
au->info = in;
strcpy(in->list_order, "NSDT3");
ReadGlobalCFGInfo(au, au->cfg_file, PROGRAM, ReadCFGInfo);
generic_parse_comm_line(au, argc, argv, parse_comm_line);
process_files(au, dir);
return 0;
}